<template>
  <div>
    <el-form :disabled="disableElement" :model="confirmFromDatas" :rules="rules" label-width="150px"
      ref="purchaseListFrom" style="width: 70%;margin-left:15%">
      <el-form-item label="卡入库结果文件" prop="SimCardImportResult">
        <el-button type="primary" size="mini" icon="el-icon-download" @click="downloadImportExcelResult">点击下载</el-button>
      </el-form-item>
      <el-form-item label="备注" prop="SimCardImportComment">
        <el-input type="textarea" v-model="confirmFromDatas.SimCardImportComment" />
      </el-form-item>
      <div v-if="showFormBtn" style="width: 30%;margin-left:35%;display:flex;justify-content: space-between;">
        <el-button type="primary" size="mini" @click="submitForm">提交</el-button>
        <el-button @click="resetForm" size="mini">重置</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>

import { getToken } from "../../../utils/auth";
import downloadutil from "@/api/system/sim/downloadutil";
import { flowXmlAndNode } from "../../../api/iot/flowable/definition";
import { getImportResult } from "../../../api/iot/flowable/custom";

export default {
  props: [
    'confirmFromData',
    'showFormBtn',
    'disableElement',
  ],
  data() {
    return {
      confirmFromDatas: this.confirmFromData,
      importUpload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/sim/inbound/exportImport",
      },
      rules: {
        ProvinceTelecomApprovalResult: [
          {
            required: true,
            message: "审批结果不能为空",
            trigger: "blur",
          },
        ],
      },
    }
  },
  created() {
  },
  methods: {
    /** 清空表单 */
    resetForm() {
      //请空数据
      this.confirmFromDatas = {
        ProvinceTelecomApprovalResult: "",
        ProvinceTelecomApprovalComment: "",
      };
    },
    submitForm() {
      // getImportResult(this.confirmFromDatas.SimCardImportResult).then((res) => {
        this.$refs.purchaseListFrom.validate(valid => {

          if (!valid) return false
          // 触发sumit事件
          const params = {
            formType: "ConfirmFrom",
            formData: this.confirmFromDatas
          }
          this.$emit('submit', params)
          return true
        })
      // });

    },
    downloadImportExcelResult() {

      getImportResult(this.confirmFromDatas.SimCardImportResult).then((res) => {
        let url = `/system/sim/inbound/exportExits/` + this.confirmFromDatas.SimCardImportResult;
        downloadutil.getFile(url, { fileName: "simReceiveTemplate.xlsx" });
      });

    },
  }
}
</script>
